/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : Debug.c /Project:AVOS		       **
**        Revision : 1.0                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "DebugEvent.h"

void SetWinDebugPalette_1080P(void)
{
    YUVENTRY mask_para[4] = {0,79,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 21176,0x8000 | 17752,0x8000 | 16392,17592,19496,19832,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinDebugPos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
           
    case OsdSize1080p:
            RECT StandardWindowRect = {0,0,1280,720};
            pControl->winrect = StandardWindowRect;
            CREATEWINDOWPARAM StandardWindowPara = {1,{{0,0,1280,720},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_4,0,0,0},SetWinDebugPalette_1080P};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&StandardWindowPara);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinDebug_1080P(HWND* pParent)
{

  
    HWND* pNewControl;
    CREATEWINDOWPARAM window_para = {1,{{0,0,1280,720},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_4,0,0,0},SetWinDebugPalette_1080P};
    //Create Menu Window -- 1
    pNewControl = AWCreateWinControl("TWindow","WinDebug_1080P",WS_OVERLAPPEDWINDOW,
		         0,0,1280,720,NULL, (INT32S)&window_para,NULL) ;
    pNewControl->win_id = 0 ;
//	break;
 //   	}
    return pNewControl;
}

void SetDebugConsolePos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){

    case OsdSize1080p:
 
            pControl->winrect.top = pControl->parent->winrect.top + 30;
            pControl->winrect.left = pControl->parent->winrect.left + 80;
            pControl->winrect.width = 1280;
            pControl->winrect.height = 720;
            pControl->draw_info_num = 14;
            RECT StandardDrawRect[14] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 47,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 94,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 141,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 188,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 235,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 282,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 329,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 376,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 423,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 470,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 517,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 564,1200,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 611,1200,30},
            	};
			 for(iLoop=0; iLoop < 14; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
			break;
			default: break;

            }//end of switch
           
    return;
}

INT32S DebugConsoleMsgProc_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return AWDebugOnShow(hwnd, lpParam) ;
        case WM_HIDEWINDOW:
            return AWDebugOnHide(hwnd, lpParam) ;
        case WM_PAINT:
            return AWDebugOnPaint(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlDebugConsole_1080P(HWND *pParent)
{
    //Create Control -- DebugConsole
    HWND *pNewControl = AWCreateWinControl("TControl","DebugConsole_1080P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		         0,0,1280,720,pParent,0,DebugConsoleMsgProc_1080P) ;
    pNewControl->win_id = 1 ;
    pNewControl->draw_info_num = 114;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatas[14] = {
        {0,0,0,0,(INT32U)debug_string[0],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[1],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[2],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[3],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[4],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[5],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[6],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[7],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[8],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[9],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[10],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[11],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[12],DT_STRING_DATA},
        {0,0,0,0,(INT32U)debug_string[13],DT_STRING_DATA}};
    memcpy(pNewControl->draw_info, DrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;

    return pNewControl;
}

void SetDebugPagePos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
    case OsdSize1080p:
            pControl->winrect.top = pControl->parent->winrect.top + 680;
            pControl->winrect.left = pControl->parent->winrect.left + 530;
            pControl->winrect.width = 220;
            pControl->winrect.height = 30;
            pControl->draw_info_num = 1;
            RECT StandardDrawRect[1] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,200,30},
            };
		 for(iLoop=0; iLoop < 1; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
       break;
	default:break;
    }//end of switch
    return;
}

INT32S DebugPageMsgProc_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_PAINT:
            return DebugPageOnPaint(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return DebugPageOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlDebugPage_1080P(HWND *pParent)
{
    //Create Control -- DebugPage
    HWND *pNewControl = AWCreateWinControl("TControl","DebugPage_1080P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		         530,680,220,30,pParent,0,DebugPageMsgProc_1080P) ;
    pNewControl->win_id = 2 ;
    pNewControl->draw_info_num = 1;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatas[1] = {
        {0,0,0,0,(INT32U)debug_page,DT_STRING_DATA}};
    memcpy(pNewControl->draw_info, DrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;

    return pNewControl;
}

HWND* CreateMenuWinDebug_1080P(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinDebug = CreateControlWinDebug_1080P(NULL);
    SetWinDebugPos_1080P(pWinDebug,CurrentOsdSize);

    pNewControl= CreateControlDebugConsole_1080P(pWinDebug);
    SetDebugConsolePos_1080P(pNewControl,CurrentOsdSize);

    pNewControl= CreateControlDebugPage_1080P(pWinDebug);
    SetDebugPagePos_1080P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinDebug;
    pWin->pFocusControl = AWFindWinCtrlByName("DebugPage_1080P");
    return pWinDebug;
}

void WinResetWinDebugControlsPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinDebug
            SetWinDebugPos_1080P(pControl,CurOsdSize) ;
            break ;
        case 1://DebugConsole
            SetDebugConsolePos_1080P(pControl,CurOsdSize) ;
            break ;
        case 2://DebugPage
            SetDebugPagePos_1080P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinDebugPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinDebug_1080P");
    if(pControl == NULL) return ;

    WinResetWinDebugControlsPos_1080P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinDebugPos_1080P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}